import scrapy
from lxml import etree
from ..items import FaceItem
import re


class FaceeSpider(scrapy.Spider):
    name = 'facee'
    allowed_domains = ['www.biquwx.la']
    start_urls = ['https://www.biquwx.la/40_40152/1152260.html']

    def parse(self, response):
        item = FaceItem()
        html = etree.HTML(response.text)
        item['chapter'] = html.xpath('//*[@id="wrapper"]/div[5]/div/div[2]/h1/text()')
        item['content'] = html.xpath('//*[@id="content"]/text()')
        next_page = html.xpath('//*[@id="wrapper"]/div[5]/div/div[2]/div[1]/a[4]/@href')
        yield item
        if re.search('大结局', item['chapter'][0]) == None:
            yield scrapy.Request(next_page[0], callback=self.parse)

